package com.emuporium.gymrat.server.routine;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.emuporium.gymrat.server.data.RoutineDB;
import com.emuporium.gymrat.server.data.User;
import com.emuporium.gymrat.server.data.UserDB;

@SuppressWarnings("serial")
public class RoutineVoteServlet extends HttpServlet {
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		int routineId = new Integer(request.getParameter("id"));
		User user = UserDB.selectUser(request.getRemoteUser());
		int userId = user.getId();
		int vote = new Integer(request.getParameter("vote"));
		
		
		RoutineDB.vote(routineId, userId, vote);

		request.setAttribute("redirecturl", "/routine/list");
		String url = "/includes/redirect.jsp";
		RequestDispatcher dispatcher = getServletContext()
				.getRequestDispatcher(url);
		dispatcher.forward(request, response);
	}

}
